@echo off
chcp 65001 >nul
cd /d "%~dp0"

REM 创建日志目录（如果不存在）
if not exist "..\logs" mkdir "..\logs"

REM 启动后端服务并将输出重定向到日志文件
echo [%date% %time%] 后端服务启动中... > "..\logs\backend_startup.log"
echo [%date% %time%] 后端服务启动中...

npm start 2>&1 | tee -a "..\logs\backend.log"

if %errorlevel% neq 0 (
    echo [%date% %time%] 后端服务启动失败，错误代码: %errorlevel% >> "..\logs\backend_startup.log"
    echo [%date% %time%] 后端服务启动失败，错误代码: %errorlevel%
) else (
    echo [%date% %time%] 后端服务启动成功 >> "..\logs\backend_startup.log"
    echo [%date% %time%] 后端服务启动成功
)

pause